#coding=utf-8

import requests,json,time
import pymysql
# 完成登录，提取token
url='http://172.16.70.246/test/oa_auth/login'
headers={'Content-Type': 'application/json'}
data={}
data['userNumber']='20280'
data['password']='000000'
ree = requests.post(url,data=json.dumps(data),headers=headers)
re=json.loads(ree.content)
token = re['data']['token']
print (token)

# clientId= "391"
# accountManagerName= "孙彪"
# organizationId= 257
# clientOrganizationId= "1208"
#
# # 提交待入职信息
timestamp = int(time.time())
name='徐'+str(timestamp)[5:10]
phone='188'+str(timestamp)[2:10]
url1=('http://172.16.70.246/test/oa_personnel/entrant/saveEntrantInfo')
headers1={'Authorization':token,'Content-Type':'application/json'}
data1={
                    "employeePhone": phone,
                    "attributionInfo": [
                        "1",
                        "1"
                    ],
                    "employeeName": name,
                    "employeeSex": "女",
                    "contactWay": "",
                    "email": phone +'@139.com',
                    "startEntrantDate": "",
                    "endEntrantDate": "",
                    "clientId": "391",
                    "accountManagerName": "孙彪",
                    "isHaveInstitutionalContracts": 1,
                    "counselorNumber": "20280",
                    "organizationId": 257,
                    "client2Id": "",
                    "postId": "55",
                    "employeeId": "",
                    "departmentId": "",
                    "employeeStatus": "",
                    "counselor": "",
                    "remark": "备注",
                    "contractSerial": "dj343",
                    "entryDate": "2024-01-11",
                    "resumeFileId": 95876,
                    "clientOrganizationId": "1208",
                    "postLevelId": "41",
                    "attributionId": "1",
                    "branchCompanyId": "1",
                    "websiteName": "智联招聘",
                    "duty": "职责"
                }
# re1 = requests.post(url1,data=json.dumps(data1),headers=headers1)
# print (name,phone)
# print (re1.content)
#
# # 完成员工性格测评
mysql_host = '172.16.70.246'
mysql_port = '3306'
mysql_user = 'root'
mysql_passwd = 'deke@2022'
mysql_database = 'test246'
conn = pymysql.connect(host=mysql_host, user=mysql_user, passwd=mysql_passwd,charset='utf8', db=mysql_database)
cursor = conn.cursor()
# sql1="select id from entrant where employee_name=%s;"
# param = (name,)
# cursor.execute(sql1,param)
# result=cursor.fetchall()
# for i in result:
#     id=i[0]
# sql2="INSERT INTO `test246`.`employee_personality_assessment` (`personality_assessment_id`, `activity_id`, `entrant_id`, `evaluation_progress`, `evaluation_results`, `answer_url`, `evaluation_results_url`, `effective_time`, `expiration_time`, `email`, `cc`, `title`, `content`, `operator_id`, `is_deleted`, `gmt_create`, `gmt_modify`) VALUES (NULL, 958685, %s, 15, 0, 'https://derkee.ceping.com/Login/Elink?elink=hyGLkE7s3E7WNgd2MFSFscxOCbaMzxcChina25EigVVYMdsBvmYivCCZq/nP2M/zmtg5wBYZ65rhy', '72176,72177', '2024-01-09 16:23:00', '2024-01-09 16:23:00', '', '', '', '', '007', 0, '2024-01-09 16:23:00', '2024-01-09 16:23:00');"
# param2 = (id,)
# cursor.execute(sql2,param2)
# conn.commit()
# sql3="INSERT INTO `test246`.`employment_contract` (`id`, `entrant_id`, `employee_id`, `contract_issue_date`, `start_date`, `stop_date`, `automatic_reminder`, `try_out_salary`, `positive_salary`, `operator_id`, `is_deleted`, `created_at`, `updated_at`, `deleted_at`, `template_serial`, `emp_contract_serial`, `emp_contract_status`, `operation_type`, `effective_contract`, `is_protocol`, `last_emp_contract_serial`, `emp_unit_price`) VALUES (NULL, %s, NULL, NULL, '2022-01-11', '2024-03-28', NULL, 9000.00, 10000.00, NULL, 0, '2024-01-15 14:48:56', '2024-01-15 15:01:38', NULL, '1800666d78134aaaaecf5d461fe81625', 'e3b7b082dc9f4c9e8bc0ec4992c95d73', 5, '10', NULL, NULL, '031faf67b9624aa8b17491acb6c50a2c', NULL);"
# param3=(id,)
# cursor.execute(sql3,param3)
# conn.commit()
#
# # 发起入职申请流程
url2='http://172.16.70.246/test/oa_personnel/entrantNewFlow/creatEntrantNewFlow'
headers2={'Authorization':token,'Content-Type':'application/json'}
data2={
    "entrantId": id,
    "employeeName": name,
    "employeeAge": 23,
    "employeeSex": "女",
    "contactWay": phone,
    "workingYears": 3,
    "websiteName": "智联招聘",
    "censusRegister": "户籍地址",
    "lastOrganization": "上家公司名称",
    "blackGrayRosterType": "",
    "authRes": "学历及真实性复核结果",
    "backgroundSurvey": "背景调查情况",
    "clientName": "抖音科技",
    "clientOrganizationName": "字节跳动",
    "isHaveInstitutionalContracts": "1",
    "clientPostName": "运营经理",
    "clientPostLevelName": "中级",
    "organizationName": "hhx第二事业部",
    "accountManagerName": "孙彪",
    "officeLocation": "办公地点",
    "employeeStatus": "0",
    "entryDate": "2024-01-11",
    "plannedAdmissionDate": "2024-01-11",
    "lossDays": "0",
    "probation": 6,
    "planRegularDate": "2024-07-11",
    "clientId": 391,
    "clientOrganizationId": 1208,
    "orgId": 257,
    "comUnitPrice": 5000,
    "salaryCalculateWay": "1",
    "tryOutWages": 5000,
    "positiveWages": 5000,
    "ssPayType": "1",
    "annualBonusType": "0",
    "attributionId": 440300,
    "workArea": [
        110000,
        110100,
        110101
    ],
    "cityOfSocial": "1",
    "ssLevelConfigId": "2",
    "socialSecurityPaymentLevel": "非深户二档",
    "ssPfgSerial": "SZ00017",
    "entryGrossProfitMargin": -32.58,
    "customerMinimumGrossMargin": "",
    "remark": "备注",
    "enclosure": "[{\"name\":\"zhaopin.pdf\",\"fileId\":\"95876\"},{\"status\":\"success\",\"name\":\"20231219-095348.png\",\"size\":469532,\"percentage\":100,\"uid\":1704962083805,\"raw\":{\"uid\":1704962083805},\"response\":{\"status\":200,\"message\":\"200\",\"page\":null,\"data\":{\"fileName\":\"20231219-095348.png\",\"fileUrl\":\"83AEFDF7D90343618696ACDEAD51BD41\",\"obsFileId\":95887,\"url\":\"https://test-deke-file.obs.cn-south-1.myhuaweicloud.com:443//employee/2024-01-11/7fc25a60-0f9a-44a1-84b6-c62be80519bb.png?AccessKeyId=I9ZCZEJISNYACIEG6MSF&Expires=1707554084&Signature=N5lqsW7VIpyUwFwS5t%2FsXGyKMJs%3D\"}}}]",
    "empFile": {
        "personalityFile": [
            {
                "name": "知识型员工心理风险因素评估报告(10).pdf",
                "fileId": 72176
            },
            {
                "name": "综合简版报告(10).pdf",
                "fileId": 72177
            }
        ],
        "backgroundFile": []
    },
    "auditConfigVO": {
        "auditConfigId": 46,
        "carbonCopy": "{\"choiceType\":\"0\",\"id\":\"10000\",\"userId\":14,\"userName\":\"胡城\"},{\"choiceType\":\"0\",\"id\":\"18736\",\"userId\":837,\"userName\":\"陈奕鑫(18736)\"},{\"choiceType\":\"0\",\"id\":\"cscc\",\"userId\":843,\"userName\":\"冲哥\"},{\"choiceType\":\"0\",\"id\":\"cici\",\"userId\":845,\"userName\":\"冲弟\"},{\"choiceType\":\"9\",\"userName\":\"\"},{\"choiceType\":\"15\",\"userName\":\"\"},{\"choiceType\":\"16\",\"userName\":\"\"}",
        "auditConfigName": "入职",
        "flowTypeName": "人资管理",
        "flowTypeId": 2,
        "createTime": "2023-01-28T12:00:00.000+00:00",
        "updateTime": "2024-01-11T08:07:16.000+00:00",
        "createBy": 1,
        "updateBy": 851,
        "createName": "admin",
        "updateName": "诸葛亮",
        "bizType": "29",
        "initiatingNodeName": "客户经理审核入职信息准确性",
        "copyNodeName": "抄送",
        "callbackUrl": "/oa_personnel/entrantNewFlow/approvedCallBackEntrantNewFlow",
        "nodeConfigs": [
            {
                "nodeConfigId": 2661,
                "nodeConfigName": "客户经理审核入职信息准确性",
                "auditConfigId": 46,
                "nodeJson": "{\"choiceType\":\"9\",\"userName\":\"\"}",
                "auditType": 0,
                "isSelfSelectNode": 1,
                "nodeOrder": 0,
                "isCallback": 0,
                "auditers": [
                    {
                        "id": "20280",
                        "label": "孙彪",
                        "children": None,
                        "deptId": "257",
                        "deptName": "",
                        "type": "1",
                        "userNumber": "20280",
                        "userName": "孙彪",
                        "userId": "886",
                        "choiceType": "9"
                    }
                ]
            },
            {
                "nodeConfigId": 2662,
                "nodeConfigName": "部门负责人审批入职",
                "auditConfigId": 46,
                "nodeJson": "{\"choiceType\":\"0\",\"id\":\"12844\",\"userId\":579,\"userName\":\"徐宇珍\"},{\"choiceType\":\"0\",\"id\":\"10497\",\"userId\":540,\"userName\":\"谭珍珍\"},{\"choiceType\":\"0\",\"id\":\"cshhx\",\"userId\":694,\"userName\":\"黄华新(cshhx)\"},{\"choiceType\":\"0\",\"id\":\"20280\",\"userId\":886,\"userName\":\"孙彪\"}",
                "auditType": 0,
                "isSelfSelectNode": 0,
                "nodeOrder": 1,
                "isCallback": 1,
                "auditers": [
                    {
                        "userId": 579,
                        "userName": "徐宇珍",
                        "choiceType": "0",
                        "id": "12844"
                    },
                    {
                        "userId": 540,
                        "userName": "谭珍珍",
                        "choiceType": "0",
                        "id": "10497"
                    },
                    {
                        "userId": 694,
                        "userName": "黄华新(cshhx)",
                        "choiceType": "0",
                        "id": "cshhx"
                    },
                    {
                        "userId": 886,
                        "userName": "孙彪",
                        "choiceType": "0",
                        "id": "20280"
                    }
                ]
            }
        ],
        "customNodes": None,
        "carbonCopiesCustomNodes": None,
        "isCallbackList": None,
        "carbonCopies": [
            {
                "userId": 14,
                "userName": "胡城",
                "choiceType": "0",
                "id": "10000"
            },
            {
                "userId": 837,
                "userName": "陈奕鑫(18736)",
                "choiceType": "0",
                "id": "18736"
            },
            {
                "userId": 843,
                "userName": "冲哥",
                "choiceType": "0",
                "id": "cscc"
            },
            {
                "userId": 845,
                "userName": "冲弟",
                "choiceType": "0",
                "id": "cici"
            },
            {
                "userId": 694,
                "userName": "黄华新(cshhx)",
                "choiceType": "15",
                "id": "cshhx"
            },
            {
                "userId": 857,
                "userName": "马超",
                "choiceType": "16",
                "id": "007"
            }
        ],
        "selfSelectCarbonCopies": True,
        "auditTypeList": None,
        "nodeConfigNameList": [],
        "auditers": []
    }
}
#
# re2 = requests.post(url2,data=json.dumps(data2),headers=headers2)
# print (re2.content)
#
# #hhx提交入职信息（相当于小程序扫码入职）
url3='http://172.16.70.246/test/oa_personnel/entrantApp/saveEntrantInfo'
headers3={'Content-Type': 'application/json'}
data3={
    "region": [
        "北京市",
        "北京市",
        "东城区"
    ],
    "nativePlace": [
        "北京市",
        "北京市",
        "东城区"
    ],
    "detailAddress": "详细地址",
    "certificateStart": "2005-12-31",
    "certificateEnd": "2015-12-31",
    "entrantTrainingExpers": [
        {
            "school": "学校培训名称",
            "speciality": "所学专业",
            "office": "学校任职",
            "certificate": "取得证书",
            "startDate": "2022-06-29",
            "endDate": "2022-06-29"
        }
    ],
    "entrantFamilies": [
        {
            "name": "家庭姓名",
            "relation": "家庭关系",
            "age": "33",
            "phone": "13539590623",
            "accumulationFund": "",
            "affiliation": "工作单位及职务"
        }
    ],
    "entrantWorkExpers": [
        {
            "organization": "工作经历公司名称",
            "department": "工作部门",
            "position": "",
            "duty": "工作职责",
            "witness": "工作证明人",
            "phone": "证明人联系电话",
            "startDate": "2022-06-29",
            "endDate": "2022-06-29"
        }
    ],
    "entrantId": id,
    "employeeName": name,
    "employeeSex": "女",
    "employeeBirthdate": "2000-06-29",
    "employeeNation": "汉",
    "censusRegister": "户籍地址",
    "idCard": 442,
    "idCardBack": 444,
    "employeeCard": "340825199303233515",
    "residentialAddress": "北京市北京市东城区详细地址",
    "employeeBirthplace": "北京市北京市东城区",
    "employeeAge": "22",
    "politicsStatus": "群众",
    "maritalStatu": "未婚",
    "fertilityStatus": "未生育",
    "documentType": "0",
    "contactWay": phone,
    "email": "HLX1@derkee.com",
    "firstEmergencyContact": "第一紧急联系人姓名",
    "firstEmergencyContactRelation": "第一关系",
    "firstEmergencyContactNumber": "13593959062",
    "firstEmergencyContactAddress": "第一地址",
    "secondEmergencyContact": "第二姓名",
    "secondEmergencyContactRelation": "第二关系",
    "secondEmergencyContactNumber": "13539590656",
    "secondEmergencyContactAddress": "第二地址",
    "degree": "博士研究生",
    "specialty": "所学专业",
    "schoolTag": "毕业院校",
    "graduationDate": "2022-06-29",
    "vocationalSkills": "专业资格证",
    "achievements": "主要业绩和成果",
    "isBank": "1",
    "bankId": 1,
    "wageCard": "4444444444444444",
    "accountOutlets": "开户网点",
    "location": "33333",
    "accumulationFund": "111111",
    "isHaveRelativesOrOtherInterests": 0,
    "relatedPersonSingleJob": "关系人担任职务",
    "illegalOrganizeWhether": 0,
    "diseaseWhether": "重大伤病记录",
    "specialtyAndHobbies": "特长或爱好",
    "otherInstructions": "其他说明",
    "personalDocument": 445,
    "personalDocumentsrc": "http://tmp/rzDhuUsfLkls694d9ba4a0694d8f7957e7146d9ea16e.png",
    "diploma": 446,
    "diplomasrc": "http://tmp/Y9lrhy563Cyg694d9ba4a0694d8f7957e7146d9ea16e.png",
    "certificate": 447,
    "certificatesrc": "http://tmp/j5YoKd3ddeb0694d9ba4a0694d8f7957e7146d9ea16e.png",
    "profQualCert": 448,
    "profQualCertsrc": "http://tmp/wmr2FCKck3pg694d9ba4a0694d8f7957e7146d9ea16e.png",
    "offiTrans": 449,
    "offiTranssrc": "http://tmp/oJhx0RnWYjdH694d9ba4a0694d8f7957e7146d9ea16e.png",
    "mediReport": 450,
    "mediReportsrc": "http://tmp/nQulRXlGx6N5694d9ba4a0694d8f7957e7146d9ea16e.png",
    "emplSepaCert": 451,
    "emplSepaCertsrc": "http://tmp/riVv8PeNGkgq694d9ba4a0694d8f7957e7146d9ea16e.png",
    "bankCard": 453,
    "bankCardsrc": "http://tmp/78ftvQt20jj2694d9ba4a0694d8f7957e7146d9ea16e.png"
}
# re3 = requests.post(url3,data=json.dumps(data3),headers=headers3)
# print (re3.content)
#
#
sql4="SELECT flow_number FROM `test246`.`audit` WHERE employee_name=%s AND audit_config_name='入职';"
param4 = (name,)
cursor.execute(sql4,param4)
conn.commit()
result=cursor.fetchall()
for i in result:
    flow_number=i[0]

sql5="SELECT audit_id FROM `test246`.`audit` WHERE `flow_number`=%s;"
param5=(flow_number,)
print(flow_number)
cursor.execute(sql5,param5)
conn.commit()
result=cursor.fetchall()
for i in result:
    audit_id=i[0]
print('流程ID:'+str(audit_id))
#
# #审批流程
# for i in range(2):
#     url4 = 'http://172.16.70.246/test/oa_audit/audit/findAuditByAuditId'
#     headers4 = {'Authorization': token, 'Content-Type': 'application/json'}
#     payload = {'auditId': audit_id}
#     re4 = requests.get(url4, params=payload, headers=headers4)
#     re4 = json.loads(re4.text)
#     # print(re4['data']['auditNodeId'])
#     # print(re4['data']['auditOrder'])
#     auditNodeId = re4['data']['auditNodeId']
#     auditOrder = re4['data']['auditOrder']
#
#     url5 = 'http://172.16.70.246/test/oa_audit/audit/examineApprove'
#     headers5 = {'Authorization': token, 'Content-Type': 'application/json'}
#     data5 = {"auditId": audit_id, "auditNodeId": auditNodeId, "auditOrder": auditOrder, "auditStatus": "1"}
#     re5 = requests.post(url5, data=json.dumps(data5), headers=headers5)
#     print(re5.text)
#
#
audit_id=13606
sql6 = "SELECT audit_status FROM `test246`.`audit` WHERE `audit_id`=%s"%(audit_id)
cursor.execute(sql6)
conn.commit()
result=cursor.fetchall()
for i in result:
    audit_status=i[0]
print(audit_status)
if audit_status == 1:
    print('流程审核通过啦')
name='徐09887'
id=419
sql7 = "SELECT employee_id FROM employee_info WHERE employee_name ='%s'"%(name)
cursor.execute(sql7)
conn.commit()
result=cursor.fetchall()
for i in result:
    employee_id=i[0]
print(employee_id)

sql8="UPDATE employee_info SET password='$2a$10$0lbPGdjNzTK40DHiRtGiU.ekDMIZ16flo0ncQqaVUrzJ2vuNfLKYm' WHERE employee_id=%s"%(employee_id)
cursor.execute(sql8)
conn.commit()

#生成合同
url6='http://172.16.70.246/test/oa_personnel/contractAgreementToSign/generateContractAgreement'
headers6 = {'Authorization': token, 'Content-Type': 'application/json'}
data6=[
    {
        "employeeId":employee_id,
        "entrantId":id,
        "employeeName":name,
        "hireDate": "2024-01-11",
        "isAdmissionRecord": 0,
        "entrantInfo": 1,
        "contractStatus": 0,
        "clientName": "抖音科技",
        "clientOrganizationName": "字节跳动",
        "orgName": "hhx第二事业部",
        "attributionName": "深圳市",
        "accountManagerName": "孙彪",
        "clientPostName": "运营经理",
        "contractNumber": 1,
        "offerAcceptState": 0,
        "employeeStatus": 0,
        "positiveDate": "2024-07-11",
        "empContractSerial": None,
        "attributionId": 1,
        "departmentId": 257,
        "refuseRemark": None,
        "signType": 0,
        "contractType": None,
        "contractObject": None,
        "employeeContractType": "1",
        "contractTemplateName": None,
        "contractEndDate": None,
        "contractStratDate": None,
        "isEmployeeSignContract": 1,
        "isPrtocolSigningCompleted": 0,
        "operate": [
            {
                "name": "生成",
                "hasBtn": "be_signed_generate"
            }
        ],
        "_X_ROW_KEY": "row_422",
        "contractSerial": "8b40a2c9ed4a428f9dc9d0877539981c",
        "agreementSerialList": [
            "8e270dba60db416894421efab50da8a6"
        ],
        "contractDateMethod": 1,
        "firstContractDate": "2024-01-01",
        "firstContractEndDate": "2026-01-01",
        "empUnitPrice": ""
    }
]
re6 = requests.post(url6, data=json.dumps(data6), headers=headers6)
print(re6.text)

#推送合同到小程序
url7='http://172.16.70.246/test/oa_personnel/laborSignEmployee/registrationAndCertification'
headers7 = {'Authorization': token, 'Content-Type': 'application/json'}
data7=[
    {
        "employeeId": employee_id,
        "entrantId": id,
        "employeeName": name,
        "hireDate": "2024-01-01",
        "isAdmissionRecord": 0,
        "entrantInfo": 1,
        "contractStatus": 5,
        "clientName": "抖音科技",
        "clientOrganizationName": "字节跳动",
        "orgName": "hhx第二事业部",
        "attributionName": "深圳市",
        "accountManagerName": "孙彪",
        "clientPostName": "运营经理",
        "contractNumber": 1,
        "offerAcceptState": 0,
        "employeeStatus": 0,
        "positiveDate": "2024-07-11",
        "empContractSerial": "7e31545bee234d308953bb63bcb8ee73",
        "attributionId": 1,
        "departmentId": 257,
        "refuseRemark": None,
        "signType": 0,
        "contractType": 1,
        "contractObject": 0,
        "employeeContractType": 1,
        "contractTemplateName": "2023初签-雇员",
        "contractEndDate": "2026-01-01",
        "contractStratDate": "2024-01-01",
        "isEmployeeSignContract": 1,
        "isPrtocolSigningCompleted": 0,
        "operate": [
            {
                "name": "重新生成",
                "hasBtn": "be_signed_rebuild"
            },
            {
                "name": "预览",
                "hasBtn": "be_signed_preview",
                "style": {
                    "color": "#FA8C16"
                }
            },
            {
                "name": "推送",
                "hasBtn": "be_signed_launch"
            }
        ],
        "_X_ROW_KEY": "row_423"
    }
]

re7 = requests.post(url7, data=json.dumps(data7), headers=headers7)
print(re7.text)
